#include "stdafx.h"

#include "time_settings.h"
#include "parameters_model.h"

TimeSettings::TimeSettings(QWeakPointer<Common> _common)
	: common(_common)
{
	init_model();
}


TimeSettings::~TimeSettings(){}

void TimeSettings::init_model(){
	//0 - combobox/boolean
	//1 - spinbox
	//2 - textbox
	//3 - label
	QString common_parameter = "COMMON";

	model = QSharedPointer<ParametersModel>(new ParametersModel(this));
	model->addItem(common_parameter, "END TIME", 0, "s", 1, 0,"11111");
	model->addItem(common_parameter, "DT", 1, "s", 1, 0,"2222222");
	model->addItem(common_parameter, "SIM SPEED", 1, "", 1, 0,"simulation speed");
	delegate = QSharedPointer<Delegate>(new Delegate(common.data()->getParametersWidget()));
	connect(model.data(), SIGNAL(ItemChanged(const QString &, const QVariant &)),
		this, SLOT(getNewParameterValue(const QString &, const QVariant &)));
	connect(this, SIGNAL(setNewParameterValue(const QString &, const QVariant &)), 
		model.data(), SLOT(changeData(const QString &, const QVariant &)));
}

void TimeSettings::update_parameters(){
	common.data()->getParametersWidget().data()->setItemDelegate(delegate.data());
}

void TimeSettings::getNewParameterValue(const QString &_name, const QVariant &_value){
	if (_name == "DT"){
		if (_value.toDouble() < 0.1)
			setNewParameterValue(_name, 0.1);
	}
}